package com.zhentao.equipment.controller;

import com.zhentao.equipment.service.DeviceGroupService;
import com.zhentao.pojo.DeviceGroup;
import com.zhentao.util.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 分组管理接口
 */
@RestController
@RequestMapping("/api/device-groups")
@CrossOrigin(origins = "*")
public class DeviceGroupController {

    @Autowired
    private DeviceGroupService service;

    /** 新增/更新分组 */
    @PostMapping
    public ResultVo save(@RequestBody DeviceGroup group) {
        return service.save(group);
    }

    /** 删除分组 */
    @DeleteMapping("/{id}")
    public ResultVo delete(@PathVariable Long id) {
        return service.delete(id);
    }

    /** 分组树 */
    @GetMapping("/tree")
    public ResultVo tree() {
        return service.tree();
    }

    /** 绑定设备（覆盖） */
    @PutMapping("/{id}/devices")
    public ResultVo bind(@PathVariable Long id, @RequestBody List<Long> deviceIds) {
        return service.bindDevices(id, deviceIds);
    }
}





